#pragma once

#include <Winsock2.h>
#include <ws2tcpip.h>

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <tchar.h>

#include <boost/exception/all.hpp>
#include <boost/exception/all.hpp>

#include "mpir/mpir.h"
//#include "opencl/openCL.h"

#include "jhlib/jhlib.h" // slim version of jh library
typedef struct  
{
	// block data (order and memory layout is important)
	uint32	version;
	uint8	prevBlockHash[32];
	uint8	merkleRoot[32];
	uint32	nBits; // Riecoin has order of nBits and nTime exchanged
	uint64	nTime; // Riecoin has 64bit timestamps
	uint8	nOffset[32];
	// remaining data
	uint32	uniqueMerkleSeed;
	uint32	height;
	uint8	merkleRootOriginal[32]; // used to identify work
	// uint8	target[32];
	// uint8	targetShare[32];
	// compact target
	uint32  targetCompact;
	uint32  shareTargetCompact;
}minerRiecoinBlock_t;

#include "crypto/sha2.h"
#include "crypto/sph_keccak.h"
#include "crypto/sph_metis.h"
#include "crypto/sph_shavite.h"

typedef boost::error_info<struct tag_LMErrorMsg, std::string> LMErrorMsg;

/// \struct  LMException
/// \brief Define the exception type, it follow boost exception concept
///
struct LMException : virtual boost::exception, virtual std::exception
{
};

/// \define  LMEXCEPTION_THROW
/// \brief Throw exception with information, or throw subexception with information
///        Basic usage:
///           LMEXCEPTION_THROW(LMException, "Try throw exception.");
#define LMEXCEPTION_THROW(EXP_TYPE, ERR_MSG) BOOST_THROW_EXCEPTION(EXP_TYPE() << LMErrorMsg(ERR_MSG))

/// \define  LMEXCEPTION_GET_DIAG_INFO
/// \brief Get exception diagnostic information, return value is std::string instance.
///        Also works for sub class of exception.
///        Basic usage:
//            ......
///           catch(LMException &ex)
///           {
///               std::string diag_info = LMEXCEPTION_GET_DIAG_INFO(ex);
///               std::cout << diag_info << std::endl;
///           }
#define LMEXCEPTION_GET_DIAG_INFO(EXP_INST)  boost::diagnostic_information(EXP_INST)

/// \define  LMEXCEPTION_GET_MSG
/// \brief Get exception error message attached while creating and throw exception, return value is std::string pointer.
///        Return a pointer because of may be not attach any RErrorMsg while creating and throw exception.
///        Also works for sub class of exception.
///        Basic usage:
///           ......
///           catch(LMException &ex)
///           {
///               std::string *err_msg = REXCEPTION_GET_MSG(ex);
///               if(err_msg)
///					std::cout << *err_msg << std::endl;
///           }
#define LMEXCEPTION_GET_MSG(EXP_INST)  boost::get_error_info<LMErrorMsg>(EXP_INST)
